//图片选择
function chooseImage(data, code,num) {
	let _this = this
	// store.state.partImgList = []
	// console.log(data,num);
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: num || 9, //默认9
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: data.sourceType || ['album', 'camera'], //从相册选择
			success: function(imgRes) {
				let imgArr = imgRes.tempFiles
				uni.showLoading({
					title: '上传中'
				})
				// 循环上传图片
				imgArr.forEach(item => {
					let data1 = Math.round(new Date() / 1000)
					let fileName = String(item.path).slice(-5)
					let urls = ''
					// 获取图片后缀
					// #ifdef H5
					let postfix = String(item.name).slice(-4)
					// #endif
					urls = data1 + fileName + postfix
					// #ifdef MP-WEIXIN
					let postfix = String(item.path).slice(-12)
					urls = data1 + postfix
					// #endif
					uni.uploadFile({
						url: 'https://xmcr.nngyun.cn/WisdomSchool/api/common/attach/upload',
						filePath: item.path,
						name: 'file',
						formData: {
							cdoe: code,
							token: res.obj.token
						},
						success: result => {
							let results = JSON.parse(result.data)
							store.state.partImgList.push({
								imgUrl: results.key
							})
							uni.hideLoading()
							if (store.state.partImgList.length === imgArr.length) {
								resolve(store.state.partImgList);
								store.state.partImgList = []
							}
						}
					
					});


				})
				// setTimeout(res=>{

				// },200)
			},
			fail: function(res) {
				console.log(res);
			}
		});
	});
}

export {
	chooseImage,
}